package com.pocketdgi.fuidemo;

import java.util.ArrayList;
import java.util.Arrays;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;

import com.pocketdigi.fui.adapters.FSpinnerAdapter;
import com.pocketdigi.fui.views.FAlertDialog;
import com.pocketdigi.fui.views.HeaderMenu;
import com.pocketdigi.fui.views.HeaderMenu.OnButtonClickListener;
import com.pocketdigi.fuidemo.R;

public class MainActivity extends Activity implements OnItemSelectedListener {

	Spinner spinner;
	AutoCompleteTextView actv;
	HeaderMenu headerMenu;
	FSpinnerAdapter spinnerAdapter;
	Button btn_dialog;
	ArrayList<String> list = new ArrayList<String>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		spinner = (Spinner) findViewById(R.id.spinner);
		actv = (AutoCompleteTextView) findViewById(R.id.actv);
		headerMenu = (HeaderMenu) findViewById(R.id.headerMenu);
		btn_dialog = (Button) findViewById(R.id.btn_dialog);
		String[] ls = getResources().getStringArray(R.array.stringarray);
		spinnerAdapter = new FSpinnerAdapter(this, Arrays.asList(ls));
		spinner.setAdapter(spinnerAdapter);
		spinner.setOnItemSelectedListener(this);

		ArrayAdapter<String> actvAdapter = new ArrayAdapter<String>(this, R.layout.item_autocompletetextview, ls);
		actv.setThreshold(1);
		actv.setAdapter(actvAdapter);

		headerMenu.setOnButtonClickListener(new OnButtonClickListener() {

			@Override
			public void onRightClicked() {
				// TODO Auto-generated method stub
				Toast.makeText(MainActivity.this, "Right Click", Toast.LENGTH_LONG).show();
			}

			@Override
			public void onLeftClicked() {
				// TODO Auto-generated method stub
				Toast.makeText(MainActivity.this, "Left Click", Toast.LENGTH_LONG).show();

			}
		});

		btn_dialog.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO 自动生成的方法存根
				FAlertDialog dialog = new FAlertDialog(MainActivity.this);
				dialog.setTitle("标题");
				dialog.setMessage("信息内容");
				dialog.setPositiveButton("确定", new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO 自动生成的方法存根
					}
				});
				dialog.setNegativeButton("取消", new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO 自动生成的方法存根
					}
				});
				dialog.show();

			}
		});

	}

	@Override
	public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
		// TODO Auto-generated method stub
		spinnerAdapter.setPosition(position);
	}

	@Override
	public void onNothingSelected(AdapterView<?> parent) {
		// TODO Auto-generated method stub

	}

}
